package zunge.twitterdel.foursquare;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;

public class ResultGenerate {
	public static void main(String args[]){
		String fu1 = "";
		String fu2 = "";
		String fd1 = "";
		
		String fou = "";
		String fod = "";
		
		try{
			process(new String[]{fu1,fu2}, fou);
			process(new String[]{fd1}, fod);
		}catch(Exception e){e.printStackTrace();}
	}
	
	static void process(String[] fins, String fout) throws Exception{
		HashMap<String,Integer> index = new HashMap<String,Integer>();
		double total = 0;
		for(String fin:fins){
			BufferedReader br = new BufferedReader(new FileReader(fin));
			String line;
			while((line=br.readLine())!=null){
				String[] frags = line.split("\t");
				if(!frags[0].equals("null")){
					index.put(frags[0], 
							index.containsKey(frags[0]) ? (index.get(frags[0])+1) : 1 );
					total++;
				}
			}
			br.close();
		}
		List<String> keyList = new ArrayList<String>(index.keySet());
		Collections.sort(keyList);
		BufferedWriter bw = new BufferedWriter(new FileWriter(fout));
		for(String key:keyList){
			bw.write(key+","+index.get(key)+","+index.get(key)/total+"\n");
		}
		bw.close();
	}
}
